<?php
namespace Admin\Controller;

class AuthController extends GroupController {
    function login() {
        if (empty($_POST['sub'])) {
            $this->display();
            exit;
        }

        //验证码
        $verify = new \Think\Verify();
        if (!$verify->check($_POST['verify'])) {
            $this->error('验证码错误！');
        }

        //检查空
        if (empty($_POST['username']) || empty($_POST['password'])) {
            $this->error('账号 / 密码 不能为空！');
        }

        //检查密码
        $res = D('Admin')->login($_POST['username'], md5($_POST['password']));
        if (!$res) {
            $this->error('密码错误！');
        }

        //登录成功
        $_SESSION['admin'] = array('id' => $res['aid'], 'username' => $_POST['username']);
        $this->redirect('Admin/Index/index');
    }

    function logout() {
        unset($_SESSION['admin']);
        $this->redirect('Admin/Index/index');
    }

    /**
     * 验证码
     */
    function verify() {
        $config = array(
            'useCurve' => false,  //混淆曲线
            'length' => 4,    //位数
            'codeSet' => '0123456789',    //字符集
        );
        $verify = new \Think\Verify($config);
        $verify->entry();
    }
}